#include <algorithm>
#include <cstdio>
#include <cstring>
#define lowbit(x) (x & -x)

typedef long long ll;
const int N = 5e5 + 5;
int n, m, a[N], hash[N], s[N], f[N];

int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }

struct BinaryIndexedArray {
  ll val[N];
  inline void modify(int x, int v) {
    while (x <= n) {
      val[x] += v;
      x += lowbit(x);
    }
  }
  inline ll query(int x) {
    ll res = 0;
    while (x) {
      res += val[x];
      x -= lowbit(x);
    }
    return res;
  }
} inv;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("sort.in", "r", stdin);
  freopen("sort.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]), hash[i] = a[i]; }
  std::sort(hash + 1, hash + n + 1);
  *hash = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i) {
    a[i] = std::lower_bound(hash + 1, hash + *hash + 1, a[i]) - hash;
  }
  ll ans = 0;
  for (int i = n; i; --i) {
    s[i] = inv.query(a[i] - 1);
    inv.modify(a[i], 1);
    ans += s[i];
  }
  for (int i = 1; i <= n; ++i) { f[i] = i; }
  f[n] = n + 1;
  f[n + 1] = n + 1;
  for (int i = 1, p; i <= m; ++i) {
    scanf("%d", &p);
    for (int j = find(p); j <= n;) {
      if (a[j] <= a[p]) {
        ans -= s[j];
        f[j] = find(j + 1);
        j = find(j);
      } else
        j = find(j + 1);
    }
    printf("%lld\n", ans);
  }
  return 0;
}